using Avalonia.Data.Converters;
using System;
using System.Globalization;

namespace DesktopApp.Converters
{
    public class ObjectToBooleanConverter : IValueConverter
    {
        public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
        {
            // Default: return true if object is not null, false if null.
            bool result = value != null;

            // Allow reversing the logic via parameter
            if (parameter is string invert && string.Equals(invert, "Invert", StringComparison.OrdinalIgnoreCase))
            {
                return !result;
            }
            return result;
        }

        public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
        {
            throw new NotImplementedException(); // Not needed for one-way bindings like IsEnabled
        }
    }
} 